import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';

class Music extends StatefulWidget {
  const Music({super.key});

  @override
  State<Music> createState() => _MusicState();
}

class _MusicState extends State<Music> {

  final AudioPlayer _audioPlayer = AudioPlayer();
  final String _musicUrl = "https://m701.music.126.net/20240918191752/fdf295a4a0d76005d71f8c5beba9e90d/jdymusic/obj/wo3DlMOGwrbDjj7DisKw/28481673965/6765/7cda/a3a0/89713a0c7a67cf997f125a4ac3390970.mp3";


  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        children: [
          Container(
            child: ElevatedButton(
              onPressed: () async{
                await _audioPlayer.play(UrlSource(_musicUrl));
              print("click");
              },
              child: Text("start"),
            ),
          ),
          Container(
            child: ElevatedButton(
              onPressed: () async{
                await _audioPlayer.pause();
                print("click");
              },
              child: Text("pause"),
            ),
          ),
        ],
      ),
    );
  }
}
